﻿@inject IStringLocalizer<ValidateForms> Localizer

<ValidateForm Model="@DynamicModel" OnInvalidSubmit="@OnInvalidDynamicModel" OnValidSubmit="@OnValidDynamicModel">
    <div class="row g-3">
        <div class="col-12 col-sm-6">
            <BootstrapInput @bind-Value="@DynamicModel.Name" />
        </div>
        <div class="col-12 col-sm-6">
            @if (ShowAddress)
            {
                <BootstrapInput @bind-Value="@DynamicModel.Address" />
            }
            else
            {
                <BootstrapInput @bind-Value="@DynamicModel.Count" />
            }
        </div>
        <div class="col-12">
            <Button ButtonType="@ButtonType.Submit" Text="@Localizer["ValidateFormsSubmitButtonText"]" />
            <Button Text="@Localizer["ChangeButtonText"]" OnClick="OnValidateChange" class="ms-3" />
            <Button Text="@Localizer["ResetButtonText"]" OnClick="OnValidateReset" class="ms-3" />
        </div>
    </div>
</ValidateForm>
<ConsoleLogger @ref="Logger" class="mt-3" />

@code {
    private bool ShowAddress { get; set; }

    [NotNull]
    private ConsoleLogger? Logger { get; set; }

    private Foo DynamicModel { get; set; } = new Foo();

    private Task OnInvalidDynamicModel(EditContext context)
    {
        Logger.Log(Localizer["OnInvalidSubmitCallBackLog"]);
        return Task.CompletedTask;
    }

    private Task OnValidDynamicModel(EditContext context)
    {
        Logger.Log(Localizer["OnValidSubmitCallBackLog"]);
        return Task.CompletedTask;
    }

    private void OnValidateChange()
    {
        ShowAddress = true;
    }

    private void OnValidateReset()
    {
        ShowAddress = false;
    }
}
